#include <cstdio>
#include <cstring>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5+10;
int a[maxn];
int h[maxn];
int re[maxn];
int main(){
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,x;
		scanf("%d %d",&n,&x);
		for(int i = 1;i<=n;i++)
		{
			scanf("%d",&a[i]);
		}
		int sum=0;
		int minn=0x3f3f3f3f;
		int maxx=-0x3f3f3f3f;
		for(int i = 1;i<=n;i++)
		{
			sum += a[i];
			if(a[i]%x!=0)
			{
				minn=min(minn,i);
				maxx=max(maxx,i);
			}
		}
		if(sum%x!=0)
		{
			printf("%d\n",n);
		}
		else if(minn!=0x3f3f3f3f)
		{
			printf("%d\n",max(maxx-1,n-(minn+1)+1));
		}
		else cout<<"-1"<<endl;
	}
	return 0;
}

